package com.baidu.controller;

/**
 * @Description:
 * @Author: 王雨超
 * @Date: 2021/12/23 11:41
 */
public class ThreadDome {
    private static Object r1=new Object();
    private static Object r2=new Object();
    public static void main(String[] args) {
        new Thread(()->{
            synchronized (r1){
                System.out.println(Thread.currentThread()+"----r1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread()+"----waiting r2");
                synchronized (r2){
                    System.out.println(Thread.currentThread()+"----r2");
                }
            }
        },"线程1").start();


        new Thread(()->{
            synchronized (r1){
                System.out.println(Thread.currentThread()+"----r2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread()+"----waiting r1");
                synchronized (r2){
                    System.out.println(Thread.currentThread()+"----r1");
                }
            }
        },"线程2").start();
    }
}
